package vip.xiaonuo.smzq.modular.xxgs.controller;

import javax.annotation.Resource;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import vip.xiaonuo.auth.core.pojo.SaBaseLoginUser;
import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
import vip.xiaonuo.smzq.modular.xxgs.entity.Xxgssj;
import vip.xiaonuo.smzq.modular.xxgs.entity.vo.JscXxgsVo;
import vip.xiaonuo.smzq.modular.xxgs.entity.vo.KcZyltjVo;
import vip.xiaonuo.smzq.modular.xxgs.entity.vo.SjscKssjyjVo;
import vip.xiaonuo.smzq.modular.xxgs.entity.param.XxgssjParam;
import vip.xiaonuo.smzq.modular.xxgs.entity.vo.XxgssjVo;
import vip.xiaonuo.smzq.modular.xxgs.service.IXxgssjService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Date;
import java.util.List;


/**
 * 信息公示_信息公示数据
 *
 * @author sqq
 * @since 2024-07-19
 */
@Api(tags = "信息公示_信息公示数据")
@RestController
@RequestMapping("/xxgs/xxgssj")
@Validated
public class XxgssjController {

    @Resource
    private IXxgssjService iXxgssjService;

    /**
     * 添加信息公示_信息公示数据
     */
    @ApiOperation("添加信息公示_信息公示数据")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid Xxgssj xxgssj) {
        //获取用户信息
        SaBaseLoginUser saBaseLoginUser = StpLoginUserUtil.getLoginUser();
        xxgssj.setDelflag(0);
        xxgssj.setCzrid(saBaseLoginUser.getId());
        xxgssj.setCzrxm(saBaseLoginUser.getName());
        xxgssj.setCzsj(DateUtil.format(new Date(), "YYYY-MM-dd"));
        iXxgssjService.save(xxgssj);
        return CommonResult.ok();
    }

    /**
     * 删除信息公示_信息公示数据
     */
    @ApiOperation("删除信息公示_信息公示数据")
    @PostMapping("/delete")
    public CommonResult<String> delete(@ApiParam(name = "pkid", value = "主键") @RequestParam String pkid) {
        Xxgssj xxgssj=iXxgssjService.getById(pkid);
        //获取用户信息
        SaBaseLoginUser saBaseLoginUser = StpLoginUserUtil.getLoginUser();
        xxgssj.setDelflag(1);
        xxgssj.setCzrid(saBaseLoginUser.getId());
        xxgssj.setCzrxm(saBaseLoginUser.getName());
        xxgssj.setCzsj(DateUtil.format(new Date(), "YYYY-MM-dd"));
        iXxgssjService.updateById(xxgssj);
        return CommonResult.ok();
    }

    /**
     * 编辑信息公示_信息公示数据
     */
    @ApiOperation("编辑信息公示_信息公示数据")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid Xxgssj xxgssj) {
        //获取用户信息
        SaBaseLoginUser saBaseLoginUser = StpLoginUserUtil.getLoginUser();
        xxgssj.setDelflag(0);
        xxgssj.setCzrid(saBaseLoginUser.getId());
        xxgssj.setCzrxm(saBaseLoginUser.getName());
        xxgssj.setCzsj(DateUtil.format(new Date(), "YYYY-MM-dd"));
        iXxgssjService.updateById(xxgssj);
        return CommonResult.ok();
    }

    /**
     * 信息公示_信息公示数据分页查询
     */
    @ApiOperation("信息公示_信息公示数据分页查询")
    @PostMapping("/list")
    public CommonResult<Page<XxgssjVo>> page(@RequestBody @Valid XxgssjParam param) {
        return CommonResult.data(iXxgssjService.page(param));
    }


    /**
     * 市级驾驶舱——信息公示
     * @param nd 年度
     */
    @ApiOperation("市级驾驶舱——信息公示")
    @GetMapping("/sjscXxgsList/{nd}")
    public CommonResult<List<JscXxgsVo>> sjscXxgsList(@PathVariable("nd") String nd) {
        return CommonResult.data(iXxgssjService.sjscXxgsList(nd));
    }

    /**
     * 市级驾驶舱——矿山数据预警
     * @param nd 年度
     */
    @ApiOperation("市级驾驶舱——矿山数据预警")
    @GetMapping("/kssjyjList/{nd}")
    public CommonResult<List<SjscKssjyjVo>> kssjyjList(@PathVariable("nd") String nd) {
        return CommonResult.data(iXxgssjService.kssjyjList(nd));
    }

    /**
     * 市级驾驶舱——资源储量统计
     * @param nd 年度
     * @param kcdm 矿山代码
     */
    @ApiOperation("市级驾驶舱——资源储量统计")
    @GetMapping("/shiZyclTj/{nd}/{kcdm}")
    public CommonResult<KcZyltjVo> shiZyclTj(@PathVariable("nd") String nd,@PathVariable("kcdm") String kcdm) {
        return CommonResult.data(iXxgssjService.shiZyclTj(nd,kcdm));
    }



}
